﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DigitalRune.Windows.Docking;

namespace SharpLab
{
    public partial class mainForm : Form
    {
        private ChartOptions ChOpt;
     
        public mainForm()
        {
            InitializeComponent();
        }

        private void mainForm_Load(object sender, EventArgs e)
        {
            GraphicForm gf1 = new GraphicForm();
            GraphicForm gf2 = new GraphicForm();
            gf1.Show(dockPanel1);
            gf2.Show(gf1.Pane, DockPaneAlignment.Bottom, 0.5);
            gf1.ChartName = "Diagramm 1";
            gf1.setChartName();
            gf2.ChartName = "Diagramm 2";
            gf2.setChartName();
            gf1.Enter += new EventHandler(gf1_Enter);
            gf2.Enter += new EventHandler(gf1_Enter);
            gf1.ShowOptions += new EventHandler(gf2_ShowOptions);
            gf2.ShowOptions += new EventHandler(gf2_ShowOptions);

            PointF[] Data = new PointF[60];
            for (int i = 0; i < 60; i++)
            {
                double x = (double)i;
                PointF pt = new PointF((float)x/10, (float)Math.Sin(x/10));
                Data[i] = pt;
            }
            gf1.Data = Data;
            gf1.Invalidate();
        }

        void gf1_Enter(object sender, EventArgs e)
        {
            if (ChOpt != null)
            {
                if (sender.GetType() == typeof(GraphicForm))
                {
                    ChOpt.GrFrm = (GraphicForm)sender;
                    ChOpt.UpdateFields();
                }
            }
        }

        void gf2_ShowOptions(object sender, EventArgs e)
        {
            if (ChOpt != null && !ChOpt.IsDisposed)
            {
                ChOpt.GrFrm = (GraphicForm)sender;
                ChOpt.Show();
            }
            else
            {
                ChOpt = new ChartOptions();
                ChOpt.GrFrm = (GraphicForm)sender;
                ChOpt.Show(dockPanel1);
                ChOpt.DockState = DigitalRune.Windows.Docking.DockState.DockRight; 
            }
        }

        private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dockPanel1.SaveAsXml("Layout.xml");
        }

        private void kommunikationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Communication comm = new Communication();
            comm.Show(dockPanel1);
        }

        private void debugToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.dbg.openDbgWindow();
        }
    }
}
